package com.example.commuinte_backed.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.commuinte_backed.mapper.BmsFollowMapper;
import com.example.commuinte_backed.model.entity.BmsFollow;
import com.example.commuinte_backed.model.entity.UmsUser;
import com.example.commuinte_backed.service.IBmsFollowService;
import com.example.commuinte_backed.service.IUmsUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;


@Service
public class IBmsFollowServiceImpl extends ServiceImpl<BmsFollowMapper, BmsFollow> implements IBmsFollowService {
    @Resource
    private IBmsFollowService iBmsFollowService;

    @Resource
    private IUmsUserService iUmsUserService;


    @Override
    public Page<UmsUser> selectUserByFollowId(Page<UmsUser> topicPage, String id) {

        Set<String> ids = this.baseMapper.selectUserByFollowId(id);

        LambdaQueryWrapper<UmsUser> wrapper = new LambdaQueryWrapper<>();

        wrapper.in(UmsUser::getId, ids);

        if(ids.size()==0)
            ids.add("0");
        return iUmsUserService.page(topicPage, wrapper);
    }
    @Override
    public Page<UmsUser> selectFollowerByUserId(Page<UmsUser> topicPage, String id){
        Set<String> ids = this.baseMapper.selectFollowerByUserId(id);
        LambdaQueryWrapper<UmsUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(UmsUser::getId, ids);
        if(ids.size()==0)
            ids.add("0");
        return iUmsUserService.page(topicPage, wrapper);
    }
}